




export class GlobalObject {
    private static dict: { [key: string]: Array<any> } = {};

    public static Add(key: string, obj: any) {
        let list = this.dict[key];
        if (list) {
            let index = list.indexOf(obj);
            if (index == -1)
                list.push(obj);
        }
        else {
            list = [obj];
            this.dict[key] = list;
        }
    }

    public static Remove(key: string, obj: any) {
        let list = this.dict[key];
        if (list) {
            let index = list.indexOf(obj);
            if (index != -1)
                list.splice(index, 1);
        }
    }

    public static Set(key: string, obj: any) {
        let list = this.dict[key];
        if (list) {
            list[0] = obj;
        }
        else {
            this.dict[key] = [obj];
        }
    }

    public static Get(key: string): any {
        let list = this.dict[key];
        if (list) {
            return list[0];
        }
        return null;
    }

    public static GetList(key: string): Array<any> | null {
        return this.dict[key];
    }
}